﻿using MySql.Data.MySqlClient;
using System;
using System.Windows;

namespace com.orange.examination
{
    public partial class WebForm3 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["admin"] == null)
            {
                Response.Redirect("../LoginAndRegister/Login.aspx");
            }
            if (!IsPostBack)
            {
                MySqlConnection conn = BaseClass.DBCon();
                conn.Open();
                MySqlCommand cmd = new MySqlCommand("select LessonName from tb_Lesson", conn);
                MySqlDataReader sdr = cmd.ExecuteReader();
                while (sdr.Read())
                {
                    ListBox1.Items.Add(sdr["LessonName"].ToString());
                }
            }
        }
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            if (txtKCName.Text == "")
            {
                Response.Write("<script type=text/javascript>alert('请输入课程名！')</script>");
                return;
            }
            else
            {
                string systemTime = DateTime.Now.ToString();
                string strsql = "insert into tb_Lesson(LessonName,LessonDataTime) values('" + txtKCName.Text.Trim() + "','" + systemTime + "')";
                BaseClass.OperateData(strsql);
                txtKCName.Text = "";
                Response.Write("<script>alert('添加成功');location='Subject.aspx'</script>");
            }
        }
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            if (ListBox1.SelectedValue.ToString() == "")
            {
                Response.Write("<script type=text/javascript>alert('请选择删除项目后删除！')</script>");
                return;
            }
            else
            {
                string strsql = "delete from tb_Lesson where LessonName='" + ListBox1.SelectedItem.Text + "'";
                BaseClass.OperateData(strsql);
                Response.Write("<script>alert('删除成功');location='Subject.aspx'</script>");
            }
        }
    }
}